package com.zareal.ymcc.fallback;

import com.zareal.ymcc.enums.GlobalErrorCode;
import com.zareal.ymcc.feign.CourseUserLearnByUserIdFeignClient;
import com.zareal.ymcc.result.JSONResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CourseUserLearnByUserIdFeignClientFallbackFactory implements FallbackFactory<CourseUserLearnByUserIdFeignClient> {
    @Override
    public CourseUserLearnByUserIdFeignClient create(Throwable throwable) {
        throwable.printStackTrace();
        log.info("获取课程购买信息失败");
        return new CourseUserLearnByUserIdFeignClient() {
            @Override
            public JSONResult selectByCourseIdAndLoginId(Long courseId, Long loginId) {
                return JSONResult.error("获取课程购买信息失败", GlobalErrorCode.COURSE_USER_BUY_INFO_GET_ERROR.getErrorMessage());
            }
        };
    }
}
